<?php
include_once "../header1.php";
?>
<script type="text/javascript">
function cleartbox()
{	
	document.getElementById("Sea_Sch").innerHTML="";
}
</script>
<script type="text/javascript">
function getHttpRequest()
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
function showHint(str)
{
var xmlhttp;    
if (str=="")
  {
  document.getElementById("List").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("List").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","sch_names.php?q="+str,true);
xmlhttp.send();
}
function fill(val)
{
document.form1.SchName.value=val;
document.getElementById("List").innerHTML="";
}
</script>
</head>
<body>
<?php
include_once ("../Login/databaseconnection.php");

$sessionSet=loggedin();
if(!isset($sessionSet))
{
require_once ("../index.php");
}
else
{

	if(isset($_POST['Register']))
	{
$New_Programme=$_POST['New_Programme'];
	$Grade=$_POST['Grade'];
		$Pro_Id=$_POST['Pro_Id'];
		$Year=$_POST['Year'];
		$No_M_Stu=$_POST['No_M_Stu'];
		$No_F_Stu=$_POST['No_F_Stu'];
		$No_Tra_tea=$_POST['No_Tera_tea'];
		$Tra_tea=$_POST['Tra_tea'];
		$Avai_Book=$_POST['Avai_Book'];
		$Avai_Tea_Gui=$_POST['Avai_Tea_Gui'];
		$SchName=$_POST['SchName'];
	$name=explode(",",$SchName);
    $nam=$name[0];
$tn=count($name);
for($i=1;$i<$tn;$i++)
{
if(empty($adr))
{
$adr=$name[$i];
}
else
{
$adr=$adr.",".$name[$i];
}
}
$results= mysql_query("SELECT * FROM school Where Name='$nam' AND Address='$adr'");
if($row = mysql_fetch_array($results))
{
 $Sch_Id=$row['School_Id'];
}
 if(($Pro_Id=="Select One"&&$New_Programme=="")||$Year==""||$SchName==""||$Grade=="")
	   {
	   $_SESSION['errorin']="All details are required Please fill all!";
	   }
	   if(($Pro_Id!="Select One"||$New_Programme!="")&&$Year!=""&&$SchName!=""&&$Grade!="")
	   {
	  $Ex_Che=mysql_query("SELECT * FROM programmes WHERE Programme_Id='$Pro_Id' AND Year='$Year' AND School_Id='$Sch_Id' AND Grade='$Grade'");
		if(mysql_num_rows($Ex_Che)!=0)
		{
			$_SESSION['errorexi']="Sorry this Programmes record already exists";
		}
		else
		{
		if($_SESSION['Access_Type']=="Teacher in Charge")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
  
   if($Sch_Id==$Own_School_Id)
	{
		require_once 'REG.php';
		}
		 else
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
		}
		}
		else if($_SESSION['Access_Type']=="Administrator")
{
require_once 'REG.php';
}   
   else
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
	}
	}
	}
?>
<?php

include_once "../header2.php";
?>
<?php
include_once "topmenu.php";
?>

<div id="content">
	<div id="main">
	  <div id="bodyfield">
<br/>
  <div id="lefttablereg">
  <form action="#" method="POST" name="form1">
  <table width="600" height="306" border="0" class="tablefontv">
    <tr>
      <td height="25" colspan="7"  scope="row"><?php
		if(isset($_POST['Register']))
{
if(isset($_SESSION['error']))
	{
	if($_SESSION['OK']=="OK")
{
echo "<font color='green'>";
	echo '<img src="../images/tick.png" width="22" height="22"/>';
	}
	else
	{
echo "<font color='red'>";
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
	}
		echo $_SESSION['error'];
		unset($_SESSION['error']);		
echo "</font>";
	}	
echo "<font color='red'>";
	if(isset($_SESSION['errorin']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errorin'];
		unset($_SESSION['errorin']);
	}
	
	if(isset($_SESSION['errorexi']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errorexi'];
		unset($_SESSION['errorexi']);
		
	}
if(isset($_SESSION['errornotallo']))
{
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['errornotallo'];
unset($_SESSION['errornotallo']);
}
echo '</font>';
}
		?></td>
      </tr>
    <tr>
      <th width="43" scope="row">&nbsp;</th>
      <td width="17" scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
     
      <td width="229" height="30" scope="row">
        
        
        Programme:</td>
        <td width="41">
        <select name="Pro_Id" id="select">
	  <?php
	  
	  if(isset($_POST['Register']))
	  {
	  $get_proname=mysql_query("SELECT * FROM programme WHERE Programme_Id='".$Pro_Id."'");
	  if($rowp=mysql_fetch_array($get_proname))
	  {
	  $Prog_name=$rowp['Programme_Name'];
	  }
	echo '<option value="'.$Pro_Id.'">'.$Prog_name.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
   
      <?php
	  $pro=mysql_query("SELECT DISTINCT(Programme_Id) FROM programme");
	  
  while($row=mysql_fetch_array($pro))
  {  
  $p_id=$row['Programme_Id'];
  	  $get_proname=mysql_query("SELECT * FROM programme WHERE Programme_Id='".$p_id."'");
	  if($rowp=mysql_fetch_array($get_proname))
	  {
  $p_name=$rowp['Programme_Name'];
	  }
if($p_id!=$Pro_Id)
{
	echo '<option value="'.$p_id.'">'.$p_name.'</option>';
}
}
   ?>
      </select><br/><label><font color="red">or</font> New programme:</label>&nbsp;&nbsp;&nbsp;
	  <?php
	  if($New_Programme!="")
	  {
	  echo "<input type='text' name='New_Programme' value='$New_Programme'/>";
	  }
	  else
	  {
	  echo "<input type='text' name='New_Programme'/>";
	  }
	  ?></td>
      <td width="144" rowspan="9"></td>
    </tr>
    <tr>
      <th scope="row">&nbsp;</th>
      <td scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
      
      <td height="26" scope="row">Year:</td><td>
        <?php
	   if(isset($_POST['Register']))
{
echo "<input type='text' name='Year' value='$Year'/>";

}
else
{
echo "<input type='text' name='Year'/>";
}?>
</td>
      </tr>
       <tr>
      <th scope="row">&nbsp;</th>
      <td scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
      
      <td height="26" scope="row">Grade:</td><td>
        <?php
	   if(isset($_POST['Register']))
{
echo "<input type='text' name='Grade' value='$Grade'/>";

}
else
{
echo "<input type='text' name='Grade'/>";

}?>
    </td></tr>
    <tr>
      <th scope="row">&nbsp;</th>
      <td scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
     
      <td height="27" scope="row">School's Name:</td>
	  <td>  
	  <?php
	  if(isset($_GET['s']))
	  {
	  $Sch_Id=$_GET['s'];
	  $snam=mysql_query("SELECT * FROM school WHERE School_Id='$Sch_Id'");
	  if($ros=mysql_fetch_array($snam))
	  {
	  $SchName=$ros['Name'].','.$ros['Address'];
	  }
	   echo "<input type='text' id='SchName' name='SchName' onKeyUp='showHint(this.value)' value='$SchName' onClick='cleartbox()' size='40' readonly='readonly'/>";
}
	  else
	  {
	 	if($_SESSION['Access_Type']=="Teacher in Charge")
{
	$NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id']; 
    $snam=mysql_query("SELECT * FROM school WHERE School_Id='$Own_School_Id'");
	  if($ros=mysql_fetch_array($snam))
	  {
	  $SchName=$ros['Name'].','.$ros['Address'];
	  }
}
	 echo "<input type='text' id='SchName' name='SchName' onKeyUp='showHint(this.value)' value='$SchName' onClick='cleartbox()' size='40' readonly='readonly'/>";
}
	else if($_SESSION['Access_Type']=="Administrator")
{
	    echo "<input type='text' id='SchName' name='SchName' onKeyUp='showHint(this.value)' value='$SchName' onClick='cleartbox()' size='40'/>";
}
}
	  ?></td>
      </tr>
    <tr>
      <th scope="row">&nbsp;</th>
      <td scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
      
      <td height="25" scope="row">Number of male students:</td><td><?php
	   if(isset($_POST['Register']))
{
echo "<input type='text' name='No_M_Stu' value='$No_M_Stu'/>";
}
else
{
echo "<input type='text' name='No_M_Stu'/>";

}?>
</td>
      </tr>
	   <tr>
      <th scope="row">&nbsp;</th>
      <td scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
      
      <td height="25" scope="row">Number of female students:</td><td> <?php
	   if(isset($_POST['Register']))
{
echo "<input type='text' name='No_F_Stu' value='$No_F_Stu'/>";
}
else
{
echo "<input type='text' name='No_F_Stu'/>";
}?>
      </td></tr>
      <tr>
        <th scope="row">&nbsp;</th>
        <td scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
    
      <td height="29" scope="row">Number of required teachers:</td> <td>
        <?php
	   if(isset($_POST['Register']))
{
echo "<input type='text' name='Required_Teachers' value='$Required_Teachers'/>";
}
else
{
echo "<input type='text' name='Required_Teachers'/>";

}?>
      </td></tr>
      
    <tr>
      <th scope="row">&nbsp;</th>
      <td scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
    
      <td height="29" scope="row">Number of teachers in training:</td> <td>
        <?php
	   if(isset($_POST['Register']))
{
echo "<input type='text' name='No_Tera_tea' value='$No_Tra_tea'/>";

}
else
{
echo "<input type='text' name='No_Tera_tea'/>";

}?>
      </td></tr>
    <tr>
      <th scope="row">&nbsp;</th>
      <td scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
      <td height="33" scope="row">Number of trained teachers:</td>  <td><?php
	   if(isset($_POST['Register']))
{
echo "<input type='text' name='Tra_tea' value='$Tra_tea'/>";

}
else
{
echo "<input type='text' name='Tra_tea'/>";

}?>
      <td></tr>
    <tr>
      <th scope="row">&nbsp;</th>
      <td scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
      
      <td height="44" scope="row">Availability of books: </td>
        <?php
		if(isset($_POST['Register']))
{
if($Avai_Book=="Yes")

{
echo '<td>';
echo '<label>';
          echo '<input type="radio" name="Avai_Book" value="Yes" checked="checked"/>';
		  echo 'Yes';
		  echo '</label>';
        echo '<br />';
       	   }
		  else
		  {
		  echo '<td>';echo '<label>';
          echo '<input type="radio" name="Avai_Book" value="Yes"/>';
          echo 'Yes';
		  echo '</label>';
		  echo '<br/>';
		  }
		  if($Avai_Book=="No")
{
        echo '<label>';
          echo '<input type="radio" name="Avai_Book" value="No" checked="checked"/>';
          echo 'No';
		  echo '</label>';
		  echo '</td>';
		  }
		  else
		  {
		   echo '<label>';
          echo '<input type="radio" name="Avai_Book" value="No" />';
          echo 'No';
		  echo '</label>';
		    echo '</td>';
			}
}
else
{
echo '<td>';echo '<label>';
          echo '<input type="radio" name="Avai_Book" value="Yes"/>';
		  
          echo 'Yes';
		  echo '</label>';
        echo '<br />';
        echo '<label>';
          echo '<input type="radio" name="Avai_Book" value="No" />';
          echo 'No';
		  echo '</label>';
		  echo '</td>';
 }
?>     </tr>
    <tr>
      <th scope="row">&nbsp;</th>
      <td scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
      <td height="18" scope="row">Availability of teachers guides:</td>        <?php
		if(isset($_POST['Register']))
{
if($Avai_Tea_Gui=="Yes")
{
echo '<td>';echo '<label>';
          echo '<input type="radio" name="Avai_Tea_Gui" value="Yes" checked="checked"/>';
		  echo 'Yes';
		  echo '</label>';
        echo '<br />';
		}
		else
		{
        echo '<td>';echo '<label>';
          echo '<input type="radio" name="Avai_Tea_Gui" value="Yes"/>';
		 echo 'Yes';
		  echo '</label>';
        echo '<br />';
		  }
		  if($Avai_Tea_Gui=="No")
{
echo '<label>';
          echo '<input type="radio" name="Avai_Tea_Gui" value="No" checked="checked"/>';
          echo 'No';
		  echo '</label>';
		  echo '</td>';
		  }
		  else
		  {
		  echo '<label>';
          echo '<input type="radio" name="Avai_Tea_Gui" value="No" />';
          echo 'No';
		  echo '</label>';
		  echo '</td>';
		  }  
}
else
{
echo '<td>';echo '<label>';
          echo '<input type="radio" name="Avai_Tea_Gui" value="Yes"/>';
		  
          echo 'Yes';
		  echo '</label>';
        echo '<br />';
        echo '<label>';
          echo '<input type="radio" name="Avai_Tea_Gui" value="No" />';
          echo 'No';
		  echo '</label>';
		  echo '</td>';
		  }
?></tr>
  </table>
  <br/>
<a href="RegPro.php" class="reset">Reset |</a>
<input name="Register" align="middle" type="submit" value="Register" class="buttonok"/>
 </form>
</div>
<div id="righttablereg">
<?php
 if($_SESSION['OK']!="OK")
{
?>
 <div class="suggestionListsch" id="List"></div>
<?php
}
		if(isset($_POST['Register']))
{
if($_SESSION['OK']=="OK")
{
if($_SESSION['Access_Type']=="Teacher in Charge")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   $result=mysql_query("SELECT * FROM programmes WHERE School_Id='$Own_School_Id'");
echo '<br/>';
if(mysql_num_rows($result)!=0)
   {
echo '<div style ="width:540px; height:500px; overflow-x:scroll; overflow-y:scroll;">';
echo '<table border="1" class="tablefontv" >
<tr bgcolor="#6AB5FF">
<td><font color="#000000">Programme Id Id</font></td>
<td><font color="#000000">Year</font></td>
<td><font color="#000000">School Id</font></td>
<td><font color="#000000">Grade</font></td>
<td><font color="#000000">Number of students</font></td>
<td><font color="#000000">Number of Teachers in training</font></td>
<td><font color="#000000">Number of trained teachers</font></td>
<td><font color="#000000">Availability of books</font></td>
<td><font color="#000000">Availability of teachers guides</font></td>
<td><font color="#000000">Last Updated Date</font></td>
</tr>';

  while($row=mysql_fetch_array($result))
  {
$Prog_Id=$_SESSION['Pro_Id'];
$Yearp=$_SESSION['Year'];
$Schoo_Id=$_SESSION['Sch_Id']; 
$Grade=$_SESSION['Grade']; 
  if($row['Programme_Id']=="$Prog_Id"&&$row['Year']=="$Yearp"&&$row['School_Id']=="$Schoo_Id"&&$row['Grade']=="$Grade")
  { $Programme_Id=$row['Programme_Id'];
  $res=mysql_query("SELECT * FROM programme WHERE Programme_Id='$Programme_Id'");
  if($rowp=mysql_fetch_array($res))
  {
  $p_name=$rowp['Programme_Name'];
  }
    echo '<tr bgcolor="#936">';
    echo '<td><font color="#000000">'.$row['Programme_Id'].'</font></td>';
    echo '<td><font color="#000000">'.$row['Year'].'</font></td>';
    echo '<td><font color="#000000">'.$row['School_Id'].'</font></td>';
    echo '<td><font color="#000000">'.$row['Grade'].'</font></td>';
    echo '<td><font color="#000000">'.$row['No_Of_Students'].'</font></td>';
	echo '<td><font color="#000000">'.$row['Teachers_In_Training'].'</font></td>';
	 echo '<td><font color="#000000">'.$row['Trained_Teachers'].'</font></td>';
       echo '<td><font color="#000000">'.$row['Availability_Books'].'</td>';
    echo '<td><font color="#000000">'.$row['Availability_Tguides'].'</td>';
	echo '<td><font color="#000000">'.$row['Last_Updated_Date'].'</font></td>';
  echo '</tr>';
  unset($_SESSION['Pro_Id']);
  unset($_SESSION['Year']);
	unset($_SESSION['Sch_Id']);
		unset($_SESSION['Grade']);
  }
 else
  {
   $Programme_Id=$row['Programme_Id'];
  $res=mysql_query("SELECT * FROM programme WHERE Programme_Id='$Programme_Id'");
  if($rowp=mysql_fetch_array($res))
  {
  $p_name=$rowp['Programme_Name'];
  }
      echo '<tr bgcolor="#CCCCCC">';
    echo '<td>'.$row['Programme_Id'].'</td>';
    echo '<td>'.$row['Year'].'</td>';
    echo '<td>'.$row['School_Id'].'</td>';
    echo '<td>'.$row['Grade'].'</td>';
    echo '<td>'.$row['No_Of_Students'].'</td>';
	echo '<td>'.$row['Teachers_In_Training'].'</td>';
	 echo '<td>'.$row['Trained_Teachers'].'</td>';
       echo '<td>'.$row['Availability_Books'].'</td>';
    echo '<td >'.$row['Availability_Tguides'].'</td>';
	 echo '<td>'.$row['Last_Updated_Date'].'</td>';
  echo '</tr>';
  }
  }
   echo "</table></div>";

  }
   }
   }
  else if($_SESSION['Access_Type']=="Administrator")
{ 
$result=mysql_query("SELECT * FROM programmes");
echo '<br/>';
if(mysql_num_rows($result)!=0)
   {
echo '<div style ="width:540px; height:500px; overflow-x:scroll; overflow-y:scroll;">';
echo '<table width="208" border="1" class="tablefontv" >
<tr bgcolor="#6AB5FF">
<td><font color="#000000">Programme Id Id</font></td>
<td><font color="#000000">Year</font></td>
<td><font color="#000000">School Id</font></td>
<td><font color="#000000">Grade</font></td>
<td><font color="#000000">Number of students</font></td>
<td><font color="#000000">Number of Teachers in training</font></td>
<td><font color="#000000">Number of trained teachers</font></td>
<td><font color="#000000">Availability of books</font></td>
<td><font color="#000000">Availability of teachers guides</font></td>
<td><font color="#000000">Last Updated Date</font></td>
</tr>';

  while($row=mysql_fetch_array($result))
  {
 $Prog_Id=$_SESSION['Pro_Id'];
$Yearp=$_SESSION['Year'];
$Schoo_Id=$_SESSION['Sch_Id'];
  $Grade=$_SESSION['Grade'];

  if($row['Programme_Id']=="$Prog_Id"&&$row['Year']=="$Yearp"&&$row['School_Id']=="$Schoo_Id"&&$row['Grade']=="$Grade")
  {
    echo '<tr bgcolor="#936">';
     echo '<td><font color="#000000">'.$row['Programme_Id'].'</font></td>';
    echo '<td><font color="#000000">'.$row['Year'].'</font></td>';
    echo '<td><font color="#000000">'.$row['School_Id'].'</font></td>';
    echo '<td><font color="#000000">'.$row['Grade'].'</font></td>';
    echo '<td><font color="#000000">'.$row['No_Of_Students'].'</font></td>';
	echo '<td><font color="#000000">'.$row['Teachers_In_Training'].'</font></td>';
	 echo '<td><font color="#000000">'.$row['Trained_Teachers'].'</font></td>';
       echo '<td><font color="#000000">'.$row['Availability_Books'].'</td>';
    echo '<td><font color="#000000">'.$row['Availability_Tguides'].'</td>';
	echo '<td><font color="#000000">'.$row['Last_Updated_Date'].'</font></td>';
  echo '</tr>';
  unset($_SESSION['Pro_Id']);
  unset($_SESSION['Year']);
  unset($_SESSION['Sch_Id']);
unset($_SESSION['Grade']);
  }
 else
  {
    echo '<tr bgcolor="#CCCCCC">';
    echo '<td>'.$row['Programme_Id'].'</td>';
    echo '<td>'.$row['Year'].'</td>';
    echo '<td>'.$row['School_Id'].'</td>';
	echo '<td>'.$row['Grade'].'</td>';
    echo '<td>'.$row['No_Of_Students'].'</td>';
	echo '<td>'.$row['Teachers_In_Training'].'</td>';
	 echo '<td>'.$row['Trained_Teachers'].'</td>';
       echo '<td>'.$row['Availability_Books'].'</td>';
    echo '<td >'.$row['Availability_Tguides'].'</td>';
	 echo '<td>'.$row['Last_Updated_Date'].'</td>';
  echo '</tr>';
  }
  }
   echo "</table></div>";
  }
  unset($_SESSION['OK']);
  }
  }
  }
  ?>
</div>
 </div>
</div>
</div>
</div>
<div id="sidebar">
<br/>
<div id="partners" class="boxed">
			<h2 class="title">PROGRAMMES</h2>
            </div>
<?php
include_once "menu.php";
?>
 <?php
include_once "../footer.php";
?>
<?php

	}
?>
</body>
</html>